<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>RVM : Life Cycle of a Compiled Method</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8">	    
    </head>

    <body>
	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
		    <tr>
			    <td valign="top" class="pagebody">
				    <div class="pageheader">
					    <span class="pagetitle">
                            RVM : Life Cycle of a Compiled Method
                                                    </span>
				    </div>
				    <div class="pagesubheading">
					    This page last changed on Jul 07, 2008 by <font color="#0050B2">dgrove</font>.
				    </div>

				    <p>In early implementations of Jikes RVM's adaptive system, compilation required holding a global lock that serialized compilation and also prevented classloading from occurring concurrently with compilation.&nbsp; This bottleneck was removed in version 2.1.0 by switching to a finer-grained locking discipline to coordinate compilation, speculative optimization, and class loading. Since no published description of this locking protocol exists outside of the source code, we briefly summarize the life cycle of a compiled method here.</p>

<p>When Jikes RVM compiles a method, it creates a compiled method object to represent this particular compilation of the source method.&nbsp; A compiled method has a unique id, and stores the compiled code and associated compiler meta-data. After a brief initialization phase, the compiled method transitions from <em>uncompiled</em> to <em>compiling</em> when compilation begins. During compilation, the optimizing compiler may perform speculative optimizations that can be invalidated by future class loading.&nbsp; Each time the compiler so speculates, it records a relevant entry in an invalidation database.&nbsp; Upon finishing compilation, the system checks to ensure that the current compilation has not already been&nbsp; invalidated by concurrent classloading.&nbsp; If it has not, then the system installs the compiled code, and subsequent&nbsp; invocations will branch to the newly created code.</p>

<p>Each time a class is loaded, the system checks the invalidation database to identify the set of compiled methods to mark as obsolete,<br/>
because this classloading action invalidates speculative optimizations previously applied to that method.&nbsp; A method may transition from either <em>compiling</em> or <em>installed</em> to <em>obsolete</em> due to a classloading-induced invalidation.&nbsp; A method can also transition from <em>installed</em> to <em>obsolete</em> when the adaptive system selects a method for optimizing recompilation and a new compiled method is installed to replace it.</p>

<p>Once a method is marked obsolete, it will never be invoked again.&nbsp; However, before the generated code for the compiled method can be garbage collected, all existing invocations of the compiled method must be complete.&nbsp; A compiled method transitions from <em>obsolete</em> to&nbsp; <em>dead</em> when no invocations of it exist on any thread stack.&nbsp; Jikes RVM detects this as part of the stack scanning phase of garbage collection; as stack frames are scanned, their compiled methods are marked as active.&nbsp; Any <em>obsolete</em> method that is not marked as active when stack scanning completes is marked as <em>dead</em> and the reference to it is removed from the compiled method table.&nbsp; It will then be freed during the next garbage collection. &nbsp;</p>

				    					    <br/>
                        <div class="tabletitle">
                            <a name="attachments">Attachments:</a>
                        </div>

                        <div class="greybox" align="left">
                                                            <img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
                                <a href="attachments/93093975/93224965.eps">compiledMethod.eps</a> (image/x-eps)
                                <br/>
                                                    </div>
				    
                    			    </td>
		    </tr>
	    </table>
	    <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td height="12" background="http://docs.codehaus.org/images/border/border_bottom.gif"><img src="images/border/spacer.gif" width="1" height="1" border="0"/></td>
			</tr>
		    <tr>
			    <td align="center"><font color="grey">Document generated by Confluence on Jul 04, 2010 19:57</font></td>
		    </tr>
	    </table>
    </body>
</html>